package com.dingwei.superiordiary.ui.activity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperTextView;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.utils.DialogUtil;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.ColumValue;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lihao on 2018/1/11.
 */

public class AutoPlayVideoSettingActivity extends BaseActivity {

    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.mobile_network)
    SuperTextView mobileNetwork;
    @Bind(R.id.wifi)
    SuperTextView wifi;
    @Bind(R.id.close)
    SuperTextView close;




    @Override
    protected int getContentViewId() {
        return R.layout.activity_auto_play_video_setting;
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        tvTitle.setText("自动播放视频设置");
        if (BaseActivity.value.getAutoPlayVideo()== ColumValue.WIFI){
            mobileNetwork.setRightIcon(0).useShape();
            wifi.setRightIcon(R.drawable.ic_gou).useShape();
            close.setRightIcon(0).useShape();
        }else if (BaseActivity.value.getAutoPlayVideo()== ColumValue.NETWORK){
            mobileNetwork.setRightIcon(R.drawable.ic_gou).useShape();
            wifi.setRightIcon(0).useShape();
            close.setRightIcon(0).useShape();
        }else if (BaseActivity.value.getAutoPlayVideo()== ColumValue.NO){
            mobileNetwork.setRightIcon(0).useShape();
            wifi.setRightIcon(0).useShape();
            close.setRightIcon(R.drawable.ic_gou).useShape();
        }
    }

    @Override
    protected void initListener() {

    }

    @OnClick({R.id.img_back, R.id.mobile_network, R.id.wifi, R.id.close})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.mobile_network:

                if (BaseActivity.value.getAutoPlayVideo() == ColumValue.NETWORK){
                    return;
                }

                DialogUtil.showAlertDialogChoose(BaseActivity.context, "温馨提示", "您是否确定切换至3G/4G和WIFI网络环境下自动播放视频", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (i) {
                            case DialogUtil.BUTTON1:
                                dialogInterface.dismiss();
                                break;
                            case DialogUtil.BUTTON2:
                                dialogInterface.dismiss();
                                mobileNetwork.setRightIcon(R.drawable.ic_gou).useShape();
                                wifi.setRightIcon(0).useShape();
                                close.setRightIcon(0).useShape();
                                BaseActivity.value.setAutoPlayVideo(ColumValue.NETWORK);
                                showSuccess();
                                break;
                        }
                    }
                });
                break;
            case R.id.wifi:
                if (BaseActivity.value.getAutoPlayVideo() == ColumValue.WIFI){
                    return;
                }
                mobileNetwork.setRightIcon(0).useShape();
                wifi.setRightIcon(R.drawable.ic_gou).useShape();
                close.setRightIcon(0).useShape();
                BaseActivity.value.setAutoPlayVideo(ColumValue.WIFI);
                showSuccess();
                break;
            case R.id.close:
                if (BaseActivity.value.getAutoPlayVideo() == ColumValue.NO){
                    return;
                }
                DialogUtil.showAlertDialogChoose(BaseActivity.context, "温馨提示", "确定关闭自动播放视频设置", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (i) {
                            case DialogUtil.BUTTON1:
                                dialogInterface.dismiss();
                                break;
                            case DialogUtil.BUTTON2:
                                dialogInterface.dismiss();
                                mobileNetwork.setRightIcon(0).useShape();
                                wifi.setRightIcon(0).useShape();
                                close.setRightIcon(R.drawable.ic_gou).useShape();
                                BaseActivity.value.setAutoPlayVideo(ColumValue.NO);
                                showSuccess();
                                break;
                        }
                    }
                });
                break;
        }
    }

    public void  showSuccess(){
        showToast("切换成功");
        finish();
    }
}
